package com.huanuo.internetofthings.service.impact.statistics;

import java.util.List;

import org.springframework.stereotype.Service;
import org.unicorn.framework.core.ResponseDto;
import org.unicorn.framework.core.exception.PendingException;

import com.huanuo.internetofthings.bo.impact.ImpactMonthStatistics;
import com.huanuo.internetofthings.bo.user.UserInfo;
import com.huanuo.internetofthings.dto.impact.ImpactDeviceStatisticsReqDto;
import com.huanuo.internetofthings.dto.statistics.ImpactDeviceGroupStatisticsRes;
import com.huanuo.internetofthings.enums.ImpactDeviceStatisticsType;
/**
 * 统计用户所在组  设备总数，在网总数、设备运行总时长
 * @author xiebin
 *
 */
@Service
public class ImpactDeviceGroupNoStatisticsService extends AbstractImpactDeviceStatisticsService {

	@Override
	public ImpactMonthStatistics getImpactMonthStatistics(UserInfo userInfo) throws PendingException {
		ImpactMonthStatistics impactMonthStatistics = new ImpactMonthStatistics();
		impactMonthStatistics.setGroupNo(userInfo.getGroupNo());
		int year = getYear();
		impactMonthStatistics.setYear(year);
		return impactMonthStatistics;
	}

	@Override
	public ResponseDto<?> calculationStatistics(List<ImpactMonthStatistics> impactMonthStatisticsList,UserInfo userInfo)
			throws PendingException {
		ImpactDeviceGroupStatisticsRes impactDeviceGroupStatisticsRes=new ImpactDeviceGroupStatisticsRes();
		//设备总数
		Integer deviceTotal = impactMonthStatisticsList.stream().mapToInt(ImpactMonthStatistics::getDeviceTotal).sum();
		impactDeviceGroupStatisticsRes.setDeviceTotal(deviceTotal);
		//设备在网总数
		Integer deviceOnlineTotal = impactMonthStatisticsList.stream().mapToInt(ImpactMonthStatistics::getDeviceOnlineTotal).sum();
		impactDeviceGroupStatisticsRes.setDeviceOnlineTotal(deviceOnlineTotal);
		//设备运行总时长
		Integer startingTimeTotal = impactMonthStatisticsList.stream().mapToInt(ImpactMonthStatistics::getStartingTimeTotal).sum();
		impactDeviceGroupStatisticsRes.setStartingTimeTotal(startingTimeTotal);
		return new ResponseDto<>(impactDeviceGroupStatisticsRes);
	}




	@Override
	public boolean supports(ImpactDeviceStatisticsReqDto s) throws PendingException {
		return ImpactDeviceStatisticsType.DeviceGroupNo.equals(s.getImpactDeviceStatisticsType());
		
	}

}